Repository navigation
codecs: the test support compiles with Clang on x86_64 Linux; dudect's base58 cases prepare by the constant-time conversion - #2
Merged
Conversation
added 2 commits
December 2, 2026 21:45
… allocation functions Clang's <mm_malloc.h>, which the x86 intrinsic headers include (Boost.URL's and Boost.JSON's <emmintrin.h>), redeclares posix_memalign without an exception specification. Clang accepts that only after a system header's declaration; after the test support's noexcept replacement it is an error, so every test that includes counting.hpp and then such a Boost header failed to compile with Clang on x86_64 Linux (the Clang 18 and Clang 22 lanes and the CI lint).
…e conversion The base58 cases encoded each class's text, unmeasured, by the public conversion, Bitcoin Core's, which exits its loops early by the bytes' values: the two classes left a different branch history before each measurement, which the measured secret operation, with no branch on the text, then read. On webcpp's main (run 46916884991, an Intel Xeon 6975P-C) base58_checksum_decode read |t| 33 to 45 in its three runs. A probe on six hosted runners (Intel Xeon 6975P-C, AMD EPYC 9V45 and 9V74), three runs each, read |t| up to 108 on the three base58 cases with that preparation and 1.3 to 4.0 with the constant-time conversion of a secure::secret<32>, which runs the same instructions for both classes, as every other case's preparation does; on an Apple M5 Max (Linux arm64 in Docker) base58_decode read 8.5 to 12.8 and then 1.4 to 2.5. The secret decode itself is unchanged: its x86-64 code has no branch on the text.
pinhopro
pushed a commit
to webcpporg/webcpp
that referenced
this pull request
Dec 3, 2026
…ix branches webcpporg/codecs#2, webcpporg/crypto#21, webcpporg/hash#18 and webcpporg/secure#2: the test support includes <mm_malloc.h> before its replaced C allocation functions (Clang on x86_64 Linux), and codecs' dudect base58 cases prepare by the constant-time conversion. Moved to their merges once they are merged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every test that includes
test/support/counting.hppand then a header that includes the x86 intrinsics failed to compile with Clang on x86_64 Linux:Clang's
<mm_malloc.h>(from<emmintrin.h>, which Boost.URL and Boost.JSON include on x86) redeclaresposix_memalignwithout an exception specification. Clang accepts that only when the declaration before it is a system header's (glibc's,__THROW); after the test support'snoexceptreplacement it is an error. GCC's<mm_malloc.h>declares itthrow (), and arm64 never includes it, so only the Clang lanes on x86_64 Linux saw it: on webcpp's main (run 46916884991) the Clang 18 and Clang 22 lanes failed to compile codecs' percent tests and crypto's formats tests, and the CI lint's clang-tidy (wasi-sdk's Clang 23, with the host target) failed shards 1, 4, 6, 7, 9 and 10. The macOS and arm64 Linux lints could not see it.The fix: the glibc branch of the test support includes
<mm_malloc.h>(when the compiler has it) before the replacements, so its redeclaration follows glibc's.Reproduced and verified on x86_64 Linux (Docker, clang++-18): codecs' percent_test.cpp and allocation_percent_test.cpp failed with that error before and compile after; the Linux lint (amd64) on the affected units.
The same change is made to the copies in secure, hash and crypto.
dudect: base58 cases prepare by the constant-time conversion
The constant-time lane on webcpp's main failed:
base58_checksum_decoderead |t| 36.12, 33.01, 44.93 (threshold 10) on an Intel Xeon 6975P-C, class 0 slower by 4 ns in 5.4 us.Cause: the harness, not the library. The base58 cases prepared each class's text, unmeasured, by the public conversion (Bitcoin Core's, with early loop exits by the bytes' values), so the two classes left a different branch history right before each measurement. The secret decode itself has no branch on the text (checked in its x86-64 code at -O3: the digit scan, the limb loop, the zero-limb scan, the checksum and its constant_time_equal are branch-free). Every other case already prepares by the same instructions for both classes.
Fix: encode the prepared texts by the constant-time conversion of a
secure::secret<32>.Evidence: a probe on six hosted x86 runners (Intel Xeon 6975P-C, AMD EPYC 9V45 and 9V74), three runs each: base58_decode, base58_encode and base58_checksum_decode read |t| up to 108 with the old preparation and 1.3 to 4.0 with the new one, on every runner. On an Apple M5 Max (Linux arm64, DIT set) base58_decode read 8.5 to 12.8 before and 1.4 to 2.5 after. The native constant-time own lane passes locally (every dudect case below 2.7, ctgrind, MemorySanitizer and the planted leaks found).
🤖 Generated with Claude Code